package com.example.handlernetimage;


import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;






import android.os.Message;
import android.util.Log;

public class NetThread extends Thread{

    private String url;
    DataReceiver receiver;


	public NetThread(String url,DataReceiver receiver){
    	this.url = url;
    	this.receiver = receiver;
    }
	
	
	@Override
	public void run() {
		HttpClient httpClient = new DefaultHttpClient();  
        HttpGet httpGet = new HttpGet(url);
        try{
        	HttpResponse httpResponse = httpClient.execute(httpGet);  
        	Log.i("1", "2");
            if(200 == httpResponse.getStatusLine().getStatusCode()){  
            	byte[] data = EntityUtils.toByteArray(httpResponse.getEntity()); 
            	Log.i("12", data.toString());
                receiver.onReceice(data);
            }  
         }catch (Exception e) {  
        	 e.printStackTrace();
         }  
	}
	
	public interface DataReceiver {
        public abstract void onReceice(byte[] s);
    }

}
